home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 26.2 KB | 853 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPPobRd.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- // ©1993-1996 Metrowerks Inc. All rights reserved.
- //
- // Portion of this code adapted from PowerPlant's UReanimator.cp & URegistrar.cp
- // in order to parse the PPob resource format.
- //
- //========================================================================================
-
- #ifndef FWPPOBRD_H
- #include "FWPPobRd.h"
- #endif
-
- #ifndef FWPPOBOB_H
- #include "FWPPobOb.h"
- #endif
-
- #ifndef FWSVIEW_H
- #include "FWSView.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWSCROLR_H
- #include "FWScrolr.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- #ifndef FWFILEOP_H
- #include "FWFileOp.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef SLFILESY_H
- #include "SLFileSy.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWMEMHLP_H
- #include "FWMemHlp.h"
- #endif
-
- #ifndef SOM_FW_OMemorySink_xh
- #include "SLMemSin.xh"
- #endif
-
- #include <stdio.h>
-
- //========================================================================================
- // Some PowerPlant Types & Constants
- //========================================================================================
-
- enum {
- tag_ObjectData = 'objd',
- tag_BeginSubs = 'begs',
- tag_EndSubs = 'ends',
- tag_Include = 'incl',
- tag_UserObject = 'user',
- tag_ClassAlias = 'dopl',
- tag_Comment = 'comm',
- tag_End = 'end.'
- };
-
- typedef long TagID;
-
- #define kLCaption_class_ID 'capt'
- #define kLDialogBox_class_ID 'dlog'
- #define kLEditField_class_ID 'edit'
- #define kLPicture_class_ID 'pict'
- #define kLGroupBox_class_ID 'gbox'
- #define kLListBox_class_ID 'lbox'
- #define kLPane_class_ID 'pane'
- #define kLStdPopupMenu_class_ID 'popm'
- #define kLScroller_class_ID 'scrl'
- #define kLActiveScroller_class_ID 'ascr'
- #define kLStdControl_class_ID 'sctl'
- #define kLStdButton_class_ID 'pbut'
- #define kLStdCheckBox_class_ID 'cbox'
- #define kLStdRadioButton_class_ID 'rbut'
- #define kLTextEdit_class_ID 'text'
- #define kLView_class_ID 'view'
- #define kLWindow_class_ID 'wind'
- #define kLRadioGroup_class_ID 'radg'
- #define kLTabGroup_class_ID 'tabg'
-
- const ResIDT Txtr_SystemFont = 0;
- #define fontNumber_Unknown -1
-
- #pragma options align=mac68k
-
- typedef struct TextTraitsRecord {
- short size;
- short style;
- short justification;
- short mode;
- RGBColor color;
- short fontNumber;
- Str255 fontName;
- } TextTraitsRecord, *TextTraitsPtr, **TextTraitsH;
-
- struct SWindowInfo {
- ResIDT WINDid;
- short layer;
- unsigned long attributes;
- short minimumWidth;
- short minimumHeight;
- short maximumWidth;
- short maximumHeight;
- short standardSize[2];
- long userCon;
- };
-
- #pragma options align=reset
-
- enum {
- windAttr_Modal = 0x80000000,
- windAttr_Floating = 0x40000000,
- windAttr_Regular = 0x20000000,
- windAttr_CloseBox = 0x10000000,
- windAttr_TitleBar = 0x08000000,
- windAttr_Resizable = 0x04000000,
- windAttr_SizeBox = 0x02000000,
- windAttr_Zoomable = 0x01000000,
- windAttr_ShowNew = 0x00800000,
- windAttr_Enabled = 0x00400000,
- windAttr_Targetable = 0x00200000,
- windAttr_GetSelectClick = 0x00100000,
- windAttr_HideOnSuspend = 0x00080000,
- windAttr_DelaySelect = 0x00040000,
- windAttr_EraseOnUpdate = 0x00020000
- };
-
- //========================================================================================
- // FW_CPPobReader Static Members
- //========================================================================================
-
- short FW_CPPobReader::gClassCount = 0;
- ClassTableH FW_CPPobReader::gTableH;
- FW_CSuperView* FW_CPPobReader::gDefaultSuperView = 0;
- PaneIDT FW_CPPobReader::gDefaultButtonID = 0;
- PaneIDT FW_CPPobReader::gCancelButtonID = 0;
- FW_CPPobScrollBarScroller* FW_CPPobReader::gScroller = 0;
- FW_PFileSpecification* FW_CPPobReader::gCurResFileSpec = 0;
- FW_Boolean FW_CPPobReader::gUseClassAlias = false;
- FW_Boolean FW_CPPobReader::gFoundViewWithAlias = false;
- FW_Boolean FW_CPPobReader::gUseDebugWarnings = true;
-
- //========================================================================================
- // class FW_CPPobReader
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwppob
- #endif
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::CreateSubViewsFromPPobResource
- // ---------------------------------------------------------------------------
-
- FW_PlatformError FW_CPPobReader::CreateSubViewsFromPPobResource(Environment* ev,
- FW_ResourceID resourceID,
- FW_CSuperView* superview,
- FW_MReceiver* receiver,
- EResourceFileKind resFileKind,
- FW_Boolean useDebugWarnings)
- {
- FW_PlatformError error = FW_xNoError;
-
- // Reset globales
- gDefaultSuperView = superview;
- gScroller = 0;
- gDefaultButtonID = 0;
- gCancelButtonID = 0;
- gFoundViewWithAlias = false;
- gUseDebugWarnings = useDebugWarnings;
-
- // Pick the right resource file
- FW_PResourceFile* resFile = GetResFile(ev, resFileKind);
-
- // Try to find the PPob view resource
- FW_TRY
- {
- // Read the WIND resource if there is one
- SetWindow(ev, *resFile, resourceID);
-
- // Create stream from PPob resource
- FW_PResource ppobResource(ev, *resFile, resourceID, FW_kPPobType);
- FW_PResourceSink sink(ev, ppobResource);
- FW_CReadableStream ppobStream(sink);
-
- // PPob version is first data in the stream
- short ppobVersion;
- ppobStream >> ppobVersion;
- if(ppobVersion != 2)
- error = FW_xWrongViewResourceVersion;
- else
- {
- // Read objects and create ODF views
- ObjectsFromStream(ev, ppobStream);
-
- // Use RidL resource to link controls to the supplied receiver
- if (receiver)
- PrivLinkReceiver(ev, *resFile, receiver, superview, resourceID);
-
- // Propagate the PostCreate method to finish creating the views
- PostCreateViewFromStream(ev, superview);
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_REFERENCE(FW_XException, except)
- {
- error = except.GetPlatformError();
- }
- FW_CATCH_EVERYTHING()
- {
- error = FW_xUnknownError;
- }
- FW_CATCH_END
-
- delete resFile;
- return error;
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::GetResFileName
- // ---------------------------------------------------------------------------
-
- void FW_CPPobReader::GetResFileName(Environment* ev, FW_CString& name)
- {
- if (gCurResFileSpec != 0)
- (*gCurResFileSpec)->GetName(ev, name);
- else
- {
- FW_PSharedLibraryResourceFile shLibFile(ev);
- FW_PFileSpecification shLibFileSpec(ev, shLibFile->GetFileSpecification(ev));
- shLibFileSpec->GetName(ev, name);
- }
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::GetResFile
- // ---------------------------------------------------------------------------
- // GetResFile returns 0 only when asking for a new resource file and cancelling
- // the file dialog. Otherwise it returns a valid external resource file or
- // the shared library itself.
-
- FW_PResourceFile* FW_CPPobReader::GetResFile(Environment* ev,
- EResourceFileKind resFileKind)
- {
- FW_PResourceFile* resFile = 0;
- OSType ppobFileTypes[] = {'rsrc', 'RSRC', 'APPL'}; // any other?
-
- if (resFileKind == kPartOnly || resFileKind == kPartOrAskUser)
- {
- resFile = FW_NEW(FW_PSharedLibraryResourceFile, (ev));
- }
- if (resFileKind == kCurrentResFile)
- {
- if (gCurResFileSpec == 0)
- {
- // Try to open the resource file ::sources:<part_name>.rsrc that was used
- // to build the project.
-
- FW_PSharedLibraryResourceFile shLibFile(ev);
- FW_PFileSpecification shLibFileSpec(ev, shLibFile->GetFileSpecification(ev));
- FW_PDirectorySpecification libDir(ev, shLibFileSpec->GetParentDirectory(ev));
- FW_CString libName;
- shLibFileSpec->GetName(ev, libName);
- FW_CString fileName(":Sources:");
- fileName += libName;
- fileName += ".ppob";
-
- gCurResFileSpec = FW_NEW(FW_PFileSpecification, (ev, libDir, fileName));
- if (FW_FileSystem_IsValidFile(ev, *gCurResFileSpec) == false)
- {
- // Else put up the file dialog
- delete gCurResFileSpec;
- gCurResFileSpec = 0;
- FW_OFileSpecification* oSpec = FW_CChooseFile::ChooseFileToOpen(
- FW_COpenFileParameters(3, ppobFileTypes));
- if (oSpec != 0)
- gCurResFileSpec = FW_NEW(FW_PFileSpecification, (ev, oSpec));
- }
- }
-
- if (gCurResFileSpec != 0)
- resFile = FW_NEW(FW_PResourceFile, (ev, *gCurResFileSpec));
- else
- resFile = FW_NEW(FW_PSharedLibraryResourceFile, (ev));
- }
- else if (resFileKind == kNewResFile)
- {
- // Ask the user to pick a new file
- FW_OFileSpecification* oSpec = FW_CChooseFile::ChooseFileToOpen(
- FW_COpenFileParameters(3, ppobFileTypes));
- if (oSpec != 0)
- {
- delete gCurResFileSpec;
- gCurResFileSpec = FW_NEW(FW_PFileSpecification, (ev, oSpec));
- }
- if (gCurResFileSpec != 0)
- resFile = FW_NEW(FW_PResourceFile, (ev, *gCurResFileSpec));
- }
-
- return resFile;
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::CreateObject
- // ---------------------------------------------------------------------------
- // Create the factory object that will read the stream and create the ODF view
-
- void* FW_CPPobReader::CreateObject(Environment* ev, FW_CReadableStream& stream,
- ClassIDT classID, ClassIDT oldClassID)
- {
- void *theObject = NULL;
-
- // Handle the case of custom Window and Dialog classes: we cannot use the
- // same UnknownView mechanism because the stream is not like LViews.
- // We revert to normal Window and Dialog objects.
- if (oldClassID == kLWindow_class_ID || oldClassID == kLDialogBox_class_ID)
- classID = oldClassID;
-
- short index = FetchClassIndex(classID);
-
- // When the flag is set we could use oldClassID instead of classID
- // if it is not registered. This will show the parent view at least.
- if (index == 0 && oldClassID != classID)
- {
- index = FetchClassIndex(oldClassID);
- if (index != 0 && gUseClassAlias == false)
- gFoundViewWithAlias = true;
- if (gUseClassAlias == false)
- index = 0;
- }
-
- if (index != 0)
- {
- theObject = (*(*gTableH)[index - 1].creatorFunc)(ev, stream, classID);
- }
- else
- {
- // When the class is not registered we create an "Unknown" object that
- // will simply read the LPane data and create an ODF Unknown view to
- // make it objvious that something is missing.
- // If a scroller was just read we can be (almost) sure that we are now
- // reading a LView instead of a LPane, so we use FW_CPPobUnknownSView
- if (FW_CPPobReader::gScroller == 0)
- theObject = new FW_CPPobUnknownView(ev, stream, classID);
- else
- theObject = new FW_CPPobUnknownSView(ev, stream, classID);
- }
- return theObject;
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::SetWindow
- // ---------------------------------------------------------------------------
-
- void FW_CPPobReader::SetWindow(Environment* ev,
- FW_PResourceFile& resFile, FW_ResourceID resourceID)
- {
- // There may not be any WIND resource associated with the PPob resource
- // in case the root view is not a window.
- FW_TRY
- {
- // Read the separate WIND resource to get the window size and location
- FW_PResource windResource(ev, resFile, resourceID, FW_kWINDType);
- FW_PResourceSink sink(ev, windResource);
- FW_CReadableStream windStream(sink);
-
- short top, left, right, bottom;
- windStream >> top >> left >> bottom >> right;
-
- // Set extent to window size
- FW_CPoint windowSize(FW_IntToFixed(right - left), FW_IntToFixed(bottom - top));
- gDefaultSuperView->SetExtent(ev, windowSize);
-
- // Set root frame's window size and location
- FW_CFrame* frame = gDefaultSuperView->GetFrame(ev);
- if (frame->IsRoot(ev))
- {
- FW_CWindow* win = frame->GetWindow(ev);
- win->SetWindowPosition(ev, FW_CPoint(FW_IntToFixed(left), FW_IntToFixed(top)));
- win->SetWindowSize(ev, windowSize);
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_REFERENCE(FW_XException, except)
- {
- // don't report missing WIND resource. We just don't change the frame.
- if (except.GetPlatformError() != FW_xResourceNotFound &&
- except.GetPlatformError() != FW_xResourceNotLoaded)
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::PrivLinkReceiver
- // ---------------------------------------------------------------------------
- // This method loads the RidL resource created by Constructor which contains the
- // list of all controls ids in the root view. It finds the ODF controls and
- // connect then to the receiver (usually the frame).
- // Note: this will link the radio buttons and check boxes as well, although
- // one usually doesn't need to respond to clicks in these kinds of buttons.
-
- void FW_CPPobReader::PrivLinkReceiver(Environment* ev, FW_PResourceFile& resFile,
- FW_MReceiver* receiver, FW_CSuperView* container, FW_ResourceID resourceID)
- {
- FW_TRY
- {
- FW_PResource ridlResource(ev, resFile, resourceID, FW_kRidLType);
- FW_PResourceSink sink(ev, ridlResource);
- FW_CReadableStream stream(sink);
-
- short count;
- long viewID;
- stream >> count;
-
- for (int i = 0; i < count; i++)
- {
- stream >> viewID;
- FW_CView* view = container->FindViewByID(ev, viewID);
- if (view == 0)
- {
- PPOB_WARNING("PPobReader Warning: found invalid viewID in RidL resource!");
- continue;
- }
-
- FW_CControl* control = FW_DYNAMIC_CAST(FW_CControl, view);
- if (control != 0)
- control->LinkControlTo(ev, receiver);
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_REFERENCE(FW_XException, except)
- {
- PPOB_WARNING("PPobReader Warning: Failed to load RidL resource.");
- }
- FW_CATCH_END
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::CreateSubViewsFromPPob
- // ---------------------------------------------------------------------------
-
- void FW_CPPobReader::LinkReceiverToControls(Environment* ev, FW_MReceiver* receiver,
- FW_CSuperView* container, FW_ResourceID resourceID)
- {
- FW_PSharedLibraryResourceFile resFile(ev);
- PrivLinkReceiver(ev, resFile, receiver, container, resourceID);
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::ObjectsFromStream
- // ---------------------------------------------------------------------------
-
- void FW_CPPobReader::ObjectsFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- ClassIDT aliasClassID = 'null';
-
- FW_CSuperView* defaultSuperView = gDefaultSuperView;
-
- FW_Boolean readingTags = true;
- do {
- void *currentObject = NULL; // Object created by current tag
- TagID theTag = tag_End;
-
- stream >> theTag;
-
- switch (theTag) {
-
- case tag_ObjectData:
- {
- gDefaultSuperView = defaultSuperView;
-
- // Object data = byte length, class ID, and then the data for the object.
- long dataLength;
- stream >> dataLength;
-
- long dataStart = ((FW_ORandomAccessSink *)stream.GetSink())->GetPosition(ev);
-
- ClassIDT classID;
- stream >> classID;
-
- ClassIDT oldClassID = classID;
-
- if (aliasClassID != 'null')
- {
- // previous tag specified an Alias for the ID of this Class.
- classID = aliasClassID;
- }
-
- // Create the factory PPob object and read the stream
- // (For unregistered classes we create a FW_CPPobUnknownView object)
- currentObject = FW_CPPobReader::CreateObject(ev, stream, classID, oldClassID);
-
- // currentObject is null only for non LView classes
- if (currentObject)
- {
- // Create the real ODF view out of the factory object
- ((FW_CPPobView *) currentObject)->CreateODFView(ev);
- }
-
- // Jump to the next object in the stream. This allows to ignore unknown classes
- ((FW_ORandomAccessSink *)stream.GetSink())->SetPosition(ev, dataStart + dataLength);
-
- aliasClassID = 'null'; // Alias is no longer in effect
- break;
- }
-
- case tag_BeginSubs:
- ObjectsFromStream(ev, stream);
- break;
-
- case tag_EndSubs:
- case tag_End:
- readingTags = false;
- break;
-
- case tag_UserObject:
- // This tag is only needed for Constructor. We can ignore it
- ClassIDT superClassID;
- stream >> superClassID;
- break;
-
- case tag_ClassAlias:
- // The ClassAlias tag defines the ClassID the for the next object
- stream >> aliasClassID;
- break;
-
- case tag_Comment:
- // The Comment tag denotes data used by PPob editors that PowerPlant ignores
- long commentLength;
- stream >> commentLength;
- long dataStart = ((FW_ORandomAccessSink *)stream.GetSink())->GetPosition(ev);
- ((FW_ORandomAccessSink *)stream.GetSink())->SetPosition(ev, dataStart + commentLength);
- break;
-
- default:
- // SignalPStr_("\pUnrecognized Tag");
- readingTags = false;
- break;
- }
-
- } while (readingTags);
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::ReadWindowPPob
- // ---------------------------------------------------------------------------
-
- void* FW_CPPobReader::ReadWindowPPob(Environment* ev,
- FW_CReadableStream& stream, ClassIDT id)
- {
- FW_UNUSED(id);
-
- // Read LWindow data
- SWindowInfo windowInfo;
- stream.Read(&windowInfo, sizeof(SWindowInfo));
-
- // Use SizeBox flag to create a FW_CGrowBox instance.
-
- FW_CFrame* frame = gDefaultSuperView->GetFrame(ev);
- if (frame->IsRoot(ev) && (windowInfo.attributes & windAttr_SizeBox))
- {
- // Grow box location is hard-coded to bottom right corner of frame
- // View id is hard-coded to 'grow' (non-root frames need to remove it)
- // (gDefaultSuperView should be the same as the frame here)
- FW_CFrame* frame = gDefaultSuperView->GetFrame(ev);
- FW_CPoint loc = frame->GetSize(ev);
- loc.x -= FW_IntToFixed(15);
- loc.y -= FW_IntToFixed(15);
- FW_CGrowBox* growBox = new FW_CGrowBox(ev, frame, 'grow', loc);
- }
-
- return 0;
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::ReadDialogPPob
- // ---------------------------------------------------------------------------
-
- void* FW_CPPobReader::ReadDialogPPob(Environment* ev,
- FW_CReadableStream& stream, ClassIDT id)
- {
- // Read the Window data first
- ReadWindowPPob(ev, stream, id);
-
- // Dialog adds the default and cancel button ids. Globales will be used
- // to test each button being created.
- stream.Read(&gDefaultButtonID, 1);
- stream.Read(&gCancelButtonID, 1);
-
- return 0;
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::RegisterAllPPClasses
- // ---------------------------------------------------------------------------
- // Register all PowerPlant classes that can create objects from Stream data
-
- void FW_CPPobReader::RegisterAllPPClasses()
- {
- // FW_CPPobReader::RegisterClass(kLStdControl_class_ID, FW_CNativeControl::Create);
- // FW_CPPobReader::RegisterClass(kLPane_class_ID, FW_CView::Create);
- FW_CPPobReader::RegisterClass(kLCaption_class_ID, FW_CPPobStaticText::Create);
- FW_CPPobReader::RegisterClass(kLEditField_class_ID, FW_CPPobEditView::Create);
- FW_CPPobReader::RegisterClass(kLGroupBox_class_ID, FW_CPPobGroupBox::Create);
- FW_CPPobReader::RegisterClass(kLListBox_class_ID, FW_CPPobListBox::Create);
- FW_CPPobReader::RegisterClass(kLPicture_class_ID, FW_CPPobPictSView::Create);
- FW_CPPobReader::RegisterClass(kLStdPopupMenu_class_ID, FW_CPPobPopupMenu::Create);
- FW_CPPobReader::RegisterClass(kLStdButton_class_ID, FW_CPPobButton::Create);
- FW_CPPobReader::RegisterClass(kLStdCheckBox_class_ID, FW_CPPobButton::Create);
- FW_CPPobReader::RegisterClass(kLStdRadioButton_class_ID,FW_CPPobButton::Create);
- FW_CPPobReader::RegisterClass(kLTextEdit_class_ID, FW_CPPobTextEdit::Create);
- FW_CPPobReader::RegisterClass(kLView_class_ID, FW_CPPobSuperView::Create);
-
- FW_CPPobReader::RegisterClass(kLScroller_class_ID, FW_CPPobScrollBarScroller::Create);
- FW_CPPobReader::RegisterClass(kLActiveScroller_class_ID,FW_CPPobScrollBarScroller::Create);
-
- FW_CPPobReader::RegisterClass(kLWindow_class_ID, ReadWindowPPob);
- FW_CPPobReader::RegisterClass(kLDialogBox_class_ID, ReadDialogPPob);
-
- FW_CPPobReader::RegisterClass(kLRadioGroup_class_ID, FW_CPPobRadioCluster::Create);
- FW_CPPobReader::RegisterClass(kLTabGroup_class_ID, FW_CPPobViewTabber::Create);
-
- #if 0
- // Powerplant classes not supported yet
- URegistrar::RegisterClass(LButton::class_ID, (ClassCreatorFunc) LButton::CreateButtonStream);
- URegistrar::RegisterClass(LPlaceHolder::class_ID, (ClassCreatorFunc) LPlaceHolder::CreatePlaceHolderStream);
- URegistrar::RegisterClass(LPrintout::class_ID, (ClassCreatorFunc) LPrintout::CreatePrintoutStream);
- URegistrar::RegisterClass('prto', (ClassCreatorFunc) LPrintout::CreateOldPrintoutStream);
-
- URegistrar::RegisterClass(LCicnButton::class_ID, (ClassCreatorFunc) LCicnButton::CreateCicnButtonStream);
- URegistrar::RegisterClass(LOffscreenView::class_ID, (ClassCreatorFunc) LOffscreenView::CreateOffscreenViewStream);
- URegistrar::RegisterClass(LTable::class_ID, (ClassCreatorFunc) LTable::CreateTableStream);
- URegistrar::RegisterClass(LIconPane::class_ID, (ClassCreatorFunc) LIconPane::CreateIconPaneStream);
- URegistrar::RegisterClass(LTextButton::class_ID, (ClassCreatorFunc) LTextButton::CreateTextButtonStream);
- #endif
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::RegisterClass
- // ---------------------------------------------------------------------------
-
- void FW_CPPobReader::RegisterClass(ClassIDT inClassID, ClassCreatorFunc inCreatorFunc)
- {
- short classIndex = 1; // One-based index into class table
-
- if (gClassCount == 0)
- {
- // Create new class table (ODNewHandle throws kODErrOutOfMemory if it fails)
- gTableH = (ClassTableH) FW_CMemoryManager::AllocateSystemHandle(sizeof(ClassTable));
- gClassCount = 1;
-
- }
- else
- {
- // See if class is already in table
- classIndex = FetchClassIndex(inClassID);
-
- if (classIndex == 0)
- {
- FW_CMemoryManager::ResizeSystemHandle((FW_PlatformHandle) gTableH,
- (gClassCount+1) * sizeof(ClassTable));
- gClassCount++;
- classIndex = gClassCount;
- }
- }
- // Store ID and CreatorFunc
- (*gTableH)[classIndex - 1].classID = inClassID;
- (*gTableH)[classIndex - 1].creatorFunc = inCreatorFunc;
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::DisposeClassTable
- // ---------------------------------------------------------------------------
- // [LSD] when should this be called?
-
- void FW_CPPobReader::DisposeClassTable()
- {
- if (gTableH != NULL) {
- FW_CMemoryManager::FreeSystemHandle((FW_PlatformHandle) gTableH);
- gTableH = NULL;
- gClassCount = 0;
- }
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::FetchClassIndex
- // ---------------------------------------------------------------------------
-
- short FW_CPPobReader::FetchClassIndex(ClassIDT inClassID)
- {
- short classIndex = 0;
- ClassTable *tableP = *gTableH;
-
- for (short i = 0; i < gClassCount; i++)
- {
- if (tableP[i].classID == inClassID)
- {
- classIndex = i + 1;
- break;
- }
- }
- return classIndex;
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::ReadStr255
- // ---------------------------------------------------------------------------
-
- FW_CString FW_CPPobReader::ReadStr255(FW_CReadableStream& stream)
- {
- char byteCount;
-
- stream >> byteCount;
-
- FW_CAcquireTemporarySystemHandle handle(byteCount);
- char* buffer = (char*) handle.GetPointer();
- stream.Read(buffer, byteCount);
-
- return FW_CString(buffer, byteCount);
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::GetTextTraits
- // ---------------------------------------------------------------------------
- // Convert PP TextTraits resource to ODF font, justification and color
- // [LSD] todo: get the transfer mode
-
- void FW_CPPobReader::GetTextTraits(short textTraitsID,
- FW_CFont& font,
- FW_TextBoxOptions& horizJust,
- FW_CColor& color)
- {
- short justification = teFlushDefault;
-
- TextTraitsH traitsHdl = 0;
- if (textTraitsID != Txtr_SystemFont)
- {
- traitsHdl = (TextTraitsH) ::GetResource('Txtr', textTraitsID);
- }
-
- if (traitsHdl != 0)
- {
- justification = (*traitsHdl)->justification;
-
- FW_CString fontName;
- fontName.ReplaceAll((*traitsHdl)->fontName);
-
- // ODF style matches Mac Style enum in Types.h
- FW_FontStyle style = (FW_FontStyle)(*traitsHdl)->style;
- int size = (*traitsHdl)->size;
- if (size == 0)
- size = 12;
-
- font = FW_CFont(fontName, style, FW_IntToFixed(size));
-
- color = (*traitsHdl)->color;
- }
- else
- {
- // Use standard system font by default
- font = FW_CFont(FW_kSystemFont);
-
- justification = ::GetSysDirection();
- color = FW_kRGBBlack;
- }
-
- // [LSD] TextTraits gives only the horizontal justification
- horizJust = FW_kTextBoxJustifyLeft;
- if(justification == teJustRight)
- horizJust = FW_kTextBoxJustifyRight;
- else if (justification == teJustCenter)
- horizJust = FW_kTextBoxJustifyHCenter;
-
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::ReloadViews
- // ---------------------------------------------------------------------------
-
- FW_PlatformError FW_CPPobReader::ReloadViews(Environment* ev,
- FW_ResourceID resourceID,
- FW_CFrame* frame,
- FW_MReceiver* receiver,
- EResourceFileKind resFileKind,
- FW_Boolean useDebugWarnings)
- {
- // Delete the whole view hierarchy under the frame
- frame->DeleteAndResetViews(ev);
-
- // Reload the views
- FW_PlatformError error = CreateSubViewsFromPPobResource(ev, resourceID, frame,
- receiver, resFileKind, useDebugWarnings);
-
- frame->Invalidate(ev);
-
- return error;
- }
-
- // ---------------------------------------------------------------------------
- // FW_CPPobReader::PostCreateViewFromStream
- // ---------------------------------------------------------------------------
- // This method is the same as FW_CSuperView::PrivPostCreateViewFromStream which
- // cannot be used in ODF 1 because it's private.
-
- void FW_CPPobReader::PostCreateViewFromStream(Environment* ev, FW_CSuperView* view)
- {
- // Handle this view first
- view->PostCreateViewFromStream(ev);
-
- // Propagate to its subviews if any
- FW_CViewIterator ite(view);
- for (FW_CView* subview = ite.First(); ite.IsNotComplete(); subview = ite.Next())
- {
- if (subview->HasSubViews(ev))
- PostCreateViewFromStream(ev, (FW_CSuperView *)subview);
- else
- subview->PostCreateViewFromStream(ev);
- }
- }
-